package ${extPackage};
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.g4studio.common.web.BaseAction;
import org.g4studio.common.web.BaseActionForm;
import org.g4studio.core.json.JsonHelper;
import org.g4studio.core.metatype.Dto;
import org.g4studio.core.metatype.impl.BaseDto;
import org.g4studio.core.mvc.xstruts.action.ActionForm;
import org.g4studio.core.mvc.xstruts.action.ActionForward;
import org.g4studio.core.mvc.xstruts.action.ActionMapping;
import org.g4studio.core.util.G4Utils;
import java.util.*;
import ${impPackage}.${className_d}ServiceImp;

/**
 * ${className}
 */
public class ${className_d}Manage extends BaseAction {

	private ${className_d}Service ${className_x}Service = ( ${className_d}Service) super.getService("${className_x}Service");

	public ActionForward ${className_x}Init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		return mapping.findForward("${className_x}List");
	}
	
	
	/**
	 * 保存实例
	 * 
	 * @param
	 * @return
	 */
	public ActionForward save${className_d}Item(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception 
	{
		BaseActionForm aForm = (BaseActionForm) form;
		Dto inDto = aForm.getParamAsDto(request);
		inDto.put("jointime", G4Utils.getCurDate());
		Dto outDto = ${className_x}Service.save${className_d}Item(inDto);
		String jsonString = JsonHelper.encodeObject2Json(outDto);
		write(jsonString, response);
		return mapping.findForward(null);
	}

	/**
	 * 删除实例
	 * 
	 * @param
	 * @return
	 */
	public ActionForward delete${className_d}Items(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String strChecked = request.getParameter("strChecked");
		Dto inDto = new BaseDto();
		
			<#list tableIndexs as tableIndex>
	<#if tableIndex.unique>
	<#if tableIndex.indexName=="PRIMARY">
		inDto.put("${tableIndex.stringCarrayNames1}", strChecked);
	
	</#if>
	</#if>
	</#list>
		${className_x}Service.delete${className_d}Items(inDto);
		setOkTipMsg("订单数据删除成功", response);
		return mapping.findForward(null);
	}

	/**
	 * 修改订单
	 * 
	 * @param
	 * @return
	 */
	public ActionForward update${className_d}Item(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		BaseActionForm aForm = (BaseActionForm) form;
		Dto inDto = aForm.getParamAsDto(request);
		${className_x}Service.update${className_d}Item(inDto);
		setOkTipMsg("订单数据修改成功", response);
		return mapping.findForward(null);
	}
	
	
	public ActionForward query${className_d}ForManage(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		BaseActionForm aForm = (BaseActionForm)form;
		Dto dto = aForm.getParamAsDto(request);
		List userList = g4Reader.queryForPage("${className_d}.query${className_d}ForManage", dto);
		Integer pageCount = (Integer) g4Reader.queryForObject("Order.query${className_d}ForManageForPageCount", dto);
		String jsonString = JsonHelper.encodeList2PageJson(userList, pageCount, null);
		write(jsonString, response);
		return mapping.findForward(null);
	}
	
	
}